<template>
  <div id="fa">
    <div>
      <h3 id="title">
        {{username}}---欢迎您!  账户转账
      </h3>
    </div>
    <Back></Back>
    <el-form :inline="true" :model="formInline" :rules="rules"  ref="formInline" class="demo-form-inline">
      <el-form-item label="卡号" prop="card">
        <el-input v-model="formInline.card" placeholder="请输入银行卡号"></el-input>
      </el-form-item>
      <el-form-item label="金额" prop="balance">
        <el-input v-model="formInline.balance" placeholder="请输入转账金额"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="save('formInline')">转账</el-button>
        <el-button type="warning" @click="resetForm('formInline')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import back from '@/components/back/Return';
import { transfer } from '@/api/info';

export default {
  name: "fa",
  data() {
    return {
      formInline: {
        card: '',
        balance: ''
      },
      username: "admin",
      //表单校验
      rules: {
        card: [
          { required: true, message: '请输入卡号', trigger: 'blur' },
          { min: 15, max: 19, message: '卡号格式不正确！', trigger: 'blur' }
        ],
        balance: [
          { required: true, message: '请输入转账或存款金额', trigger: 'blur' },
          { min: 1, message: '金额至少为1元！', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    //转账
    save(formName) {
      console.log('转账');
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert('submit!');
          //发送请求
          transfer(this.formInline).then(respone=>{
            console.log(respone);
          }).catch(error=>{
            console.log(error);
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    //重置表单
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  },
  components: {
    'Back': back
  }

}
</script>

<style scoped>
#main{
  margin: 20px 300px;
}
.balance{
  text-align: center;
  margin: 80px auto;
}
#find{
  width: 1000px;
  margin: 80px auto;
}
form.el-form.demo-form-inline.el-form--inline{
  text-align: center;
}
#title{
  line-height: 100px;
  text-align: center;
  color: #00a854;
}
</style>
